#include<bits/stdc++.h>
namespace IO{
	inline char gc(){
	static const int Rlen=1<<18|1;static char buf[Rlen],*p1,*p2;
	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
	}
	template<typename T>T get_integer(){
		char c;bool f=false;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
		while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
	}
	inline int gi(){return get_integer<int>();}
	char obuf[(int)(1e6+7)],*oh=obuf;
	inline void prt(char c){*oh++=c;}
	inline void prt(const char *s){
		while(*s)*oh++=*s++;
	}
	template<typename T>void prt(T a){
		static char ch[23];int tl=0;
		if(a<0)*oh++='-',a=-a;
		do ch[++tl]=a%10;while(a/=10);
		while(tl)*oh++=ch[tl--]^48;
	}
	template<typename T,class ...Args>
	void prt(T a,Args...args){
		prt(a),prt(args...);
	}
	struct obuf_flusher{
		~obuf_flusher(){fwrite(obuf,1,oh-obuf,stdout);}
	}Flusher;
}
using namespace std;
using namespace IO;
const int N=100010,M=200010;
int n,cnt,a[M],b[M],f[M],siz[M];
vector<int>v[M];
vector<pair<int,int> >p[N<<2];
struct s{
	int x,f,y;
};
stack<s>st;
inline int g(int x){
	if(f[x]!=x){
		return g(f[x]);
	}
	return x;
}
inline void merge(int x,int y){
	x=g(x);
	y=g(y);
	if(x!=y){
		cnt++;
		if(siz[x]>siz[y]){
			swap(x,y);
		}
		st.push({x,f[x],y});
		f[x]=y;
		siz[y]+=siz[x];
	}
}
inline void update(int x,int y,int a,int b,int l,int r,int rt){
	int mid=(l+r)>>1;
	if(x<=l&&y>=r){
		p[rt].push_back({a,b});
		return;
	}
	if(x<=mid){
		update(x,y,a,b,l,mid,rt<<1);
	}
	if(y>=mid+1){
		update(x,y,a,b,mid+1,r,rt<<1|1);
	}
}
inline void solve(int l,int r,int rt){
	int mid=(l+r)>>1,si=st.size();
	for(auto i:p[rt]){
		merge(i.first,i.second);
	}
	if(cnt==n-1){
		for(int i=l;i<=r;i++){
			prt("YES\n");
		}
		goto lass;
	}
	if(l==r){
		prt("NO\n");
	}
	else{
		solve(l,mid,rt<<1);
		solve(mid+1,r,rt<<1|1);
	}
	lass:;
	while(st.size()>si){
		cnt--;
		f[st.top().x]=st.top().f;
		siz[st.top().y]-=siz[st.top().x];
		st.pop();
	}
}
int main(){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	int m,k,c;
	n=gi();
	m=gi();
	for(int i=1;i<=n;i++){
		f[i]=i;
		siz[i]=1;
	}
	for(int i=1;i<=m;i++){
		a[i]=gi();
		b[i]=gi();
		v[i].push_back(0);
	}
	k=gi();
	for(int i=1;i<=k;i++){
		c=gi();
		while(c--){
			v[gi()].push_back(i);
		}
	}
	for(int i=1;i<=m;i++){
		v[i].push_back(k+1);
		for(int j=0;j<v[i].size()-1;j++){
			if(v[i][j]+1!=v[i][j+1]){
				update(v[i][j]+1,v[i][j+1]-1,a[i],b[i],1,k,1);
			}
		}
	}
	solve(1,k,1);
}